<?
Class ProductModule{
    var $_connect;
    var $error;
    function ProductModule() {
        $this->_connect = new Dataconnection();
    }
    function geterror(){
        return $this->error;
    }
    function getProduct($id){
        $SQLCommand="
        SELECT
            `product`.*
        FROM
            `product`
        WHERE
            `product`.`id`='$id'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        $result=array();
        if($data!=null ){
            $result=$data->fetch_array();
            return $result;
        }
        return null;
    }
    
    function getProducts($p,$n,$q){
        $str=($p-1)*$n;
        $SQLCommand="
        SELECT
            `product`.*
        FROM
            `product`
        LIMIT $str,$n
            
        ";
        
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    function getProduct_NumRow($q,$category){
        
        $SQLCommand="
        SELECT
            count(*) as numrow
        FROM
            `product`
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($data!=null ){
            $row=$data->fetch_array();
            return $row["numrow"];
        }
        return 0;
    }
    function insert($name,$title,$description,$smallimage,$image,$price,$album){
        
        $SQLCommand="
        INSERT 
            `product`(
                `name`,`title`,`description`,`smallimage`,`image`,`price`,`album`,`insert`
            )
            VALUE(
                '$name','$title','$description','$smallimage','$image','$price',',$album',now()
            )
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function update($id,$name,$title,$description,$smallimage,$image,$price,$album){
        $SQLCommand="
        UPDATE 
            `product`
        SET `name`='$name',
            `title`='$title',
            `description`='$description',
            `smallimage`='$smallimage',
            `image`='$image',
            `price`='$price',
            `album`='$album',
            `update`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function delete($id){
        $SQLCommand="
        UPDATE 
            `product`
        SET `delete`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function restore($id){
        $SQLCommand="
        UPDATE 
            `product`
        SET `delete`=null
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
}
?>